const glob = require('glob');
const path = require('path');

const pages = {};
const entries = {};
const chunks = {};

const rootPath = path.resolve(process.cwd(), 'src');

glob
  .sync('!(_*)/[!_]*', {
    cwd: rootPath,
    nodir: true
  })
  .forEach(file => {
    const absolutePath = path.resolve(rootPath, file);
    const ext = path.extname(file);
    const dirName = path.dirname(file);

    if (ext === '.ejs') {
      pages[absolutePath] = dirName;
    }

    if (ext === '.js') {
      if (entries[dirName]) {
        return;
      }
      entries[dirName] = absolutePath;
      chunks[dirName] = [dirName];
    }
  });

module.exports = {
  chunks,
  pages,
  entries
};
